﻿$(document).ready(function () {

    var oldName = '';
    $(":checkbox").each(function () {
        var newName = $(this).prop("name");
        if (oldName != newName) {
            var el = $("[name='" + newName + "']").get(0);
            var len = $("[name='" + newName + "']:checked").length;
            oldName = newName;
            el.setCustomValidity(len > 0 ? "" : "你必须选择至少一个选项");
            el.focus();
        }
    });

    $(":checkbox").change(function () {
        var name = $(this).prop("name");
        var el = $("[name='" + name + "']").get(0);
        var len = $("[name='" + name + "']:checked").length;
        el.setCustomValidity(len > 0 ? "" : "你必须选择至少一个选项");
        el.focus();
    });
});
